<?php

/**
 * theme actions.
 *
 * @package    jiazhang
 * @subpackage theme
 * @author     Your name here
 * @version    SVN: $Id: actions.class.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class themeActions extends sfActions
{
 /**
  * Executes index action
  *
  * @param sfRequest $request A request object
  */
  public function executeIndex(sfWebRequest $request)
  {
      $group_id = (int)$request->getParameter('group_id',0);
      
      if($group_id > 0){
          $dql = Doctrine::getTable('TalkTheme')->createQuery()->where('group_id = ?',$group_id)->orderBy('created_at desc');
      }else{
          $dql = Doctrine::getTable('TalkTheme')->createQuery()->orderBy('created_at desc');
      }
      
        $page = $request->getParameter('page',1);
        $this->pager = new sfDoctrinePager('TalkTheme',30);
        $this->pager->setQuery($dql);
        $this->pager->setPage($page);
        $this->pager->init();
  }
  
   public function executeChange_display(sfWebRequest $request)
  {
       
    $this->forward404Unless($theme = Doctrine::getTable('TalkTheme')->findOneById($id = (int)$request->getParameter('id')));
    $display = (int)$request->getParameter('display',0);
    $theme->setDisplay($display)->save();
    $this->getUser()->setFlash('success', '话题显示状态更改！');
    
    $this->redirect($request->getReferer());
  }
  
  public function executeShow(sfWebRequest $request){
      $this->forward404Unless($this->theme = Doctrine::getTable('TalkTheme')->findOneById($id = (int)$request->getParameter('id')));
  }
  
  public function executeChange_recommend(sfWebRequest $request)
  {
    $this->forward404Unless($group = Doctrine::getTable('TalkTheme')->findOneById($id = (int)$request->getParameter('id')));
    $recommend = (int)$request->getParameter('recommend',0);
    $group->setRecommend($recommend)->save();
    $this->getUser()->setFlash('success', '推荐成功！');
    $this->redirect($request->getReferer());
  }
}
